package com.gxljc.bear.crawler.util;

import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by jianzhou on 2016/11/25.
 */
public class RegexUtil {

    public static List<LinkedList<String>> matchAll(String regex, String s) {
        LinkedList<LinkedList<String>> res = new LinkedList<LinkedList<String>>();
        Matcher m = Pattern.compile(regex).matcher(s);
        int st = 0;
        while (m.find(st)) {
            LinkedList<String> r = new LinkedList<>();
            for (int i = 1; i <= m.groupCount(); i++) {
                r.addLast(m.group(i));
            }
            res.addLast(r);
            st = m.end();
        }
        return res;
    }
}
